package com.chenfan.mcn.enums;

import cn.hutool.core.lang.UUID;
import com.chenfan.mcn.model.dto.*;
import com.chenfan.mcn.service.impl.SettlementCommodityOutputDTO;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * 导入Excel失败枚举
 *
 * @author wulg
 * @date 2021-10-09
 **/
@SuppressWarnings("ALL")
@Getter
@AllArgsConstructor
public enum ImportExcelEnum {

    CUSTOMER_TARGET("customer_target_", "", CustomerTargetOutputDTO.class),
    FINANCE_BATCH_CONFIRM_DEVIDED("finance_batch_confirm_devided_", "", ExcutionOrderBatchConfirmOutputDTO.class),
    EXECUTION_BATCH_APPROVAL("execution_batch_approval_", "", ExcutionOrderBatchApprovalOutputDTO.class),
    BUSINESS_COMMISSION_BATCH_SAVE("business_commission_batch_save_","", BusinessCommissionBatchSaveOutDTO.class),
    BUSINESS_COMMISSION_BATCH_DELETE("business_commission_batch_delete_", "", BusinessCommissionBatchDeleteOutDTO.class),
    STAR_REBATE_EXCUTION_ORDER("star_rebate_excution_order_", "", RelatedExcutionOrderOutputDTO.class),
    SETTLEMENT_EXCUTION_ORDER("settlement_excution_order_", "", RelatedExcutionOrderOutputDTO.class),
    SETTLEMENT_ACCRUED_TAX("settlement_accrued_tax_", "", AccruedTaxOutputDTO.class),
    KOC_STAR("koc_star_", "", KocStarOutputDTO.class),
    LIVE_COMMODITY("live_commodity_", "", CommodityOutputDTO.class),
    LIVE_SETTLMENT_COMMODITY("live_settlment_commodity_", "", SettlementCommodityOutputDTO.class),
    UPDATE_STAR_PLATFORM_INFO("update_star_platform_info_", "", StarPlatformInfoOutputDTO.class),
    UPDATE_STAR_BASIC_DATA_INFO("update_star_basic_data_info_", "", StarBasicDataInfoOutputDTO.class),

    ;

    private String prefix;

    private String title;

    private Class outputClass;

    public String getFileId() {
        return this.prefix + UUID.randomUUID();
    }

    public String getTitle() {
        return StringUtils.defaultIfBlank(title, "失败原因");
    }

    public static ImportExcelEnum toEnum(String fileId) {
        if(StringUtils.isBlank(fileId)) {
            return null;
        }
        for (ImportExcelEnum item : ImportExcelEnum.values()) {
            if (fileId.startsWith(item.prefix)) {
                return item;
            }
        }
        return null;
    }

    public static boolean match(String fileId, ImportExcelEnum targetEnum) {
        ImportExcelEnum item = ImportExcelEnum.toEnum(fileId);
        if(item == null) {
            return false;
        }
        return item.equals(targetEnum);
    }
}
